package com.simple.editor.ui;

import javax.swing.*;
import javax.swing.tree.DefaultTreeCellRenderer;
import java.awt.*;

/**
 * Created with IntelliJ IDEA.
 * User: vsoroka
 * Date: 07.06.13
 * Time: 15:39
 * To change this template use File | Settings | File Templates.
 */
class ChangesPaneTreeCellRenderer extends DefaultTreeCellRenderer {


    public Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean selected, final boolean expanded,
                                                  final boolean leaf, final int row, final boolean hasFocus) {
        super.getTreeCellRendererComponent(tree, value,
                selected, expanded, leaf, row, hasFocus);

        final JLabel label = this;

        if (value instanceof ChangesNode) {
            final ChangesNode node = (ChangesNode) value;
            final FileModel file = node.getFile();

            Utils.updateLabelForTheFile(label, file);

            if (leaf) {
                setToolTipText(file.getStatus().name());
            } else {
                setToolTipText("");
            }
        } else {
            label.setFont(new Font("Verdana", Font.PLAIN, 12));
            setToolTipText("");
        }

        return this;
    }
}
